<template>
    <el-dialog v-dialog title="审核" :close-on-click-modal="false" :visible.sync="visible" @close="handleClose" :center="true">
        <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
            <el-form-item label="名称">
                <el-input v-model="dataForm.name" placeholder="" :disabled="true"></el-input>
            </el-form-item>
            <el-form-item label="类型">
                <el-input v-model="dataForm.type" placeholder="" :disabled="true"></el-input>
            </el-form-item>
            <el-form-item label="金额">
                <el-input v-model="dataForm.money" placeholder="" :disabled="true"></el-input>
            </el-form-item>
            <el-form-item label="范围">
                <el-input v-model="dataForm.range" placeholder="" :disabled="true"></el-input>
            </el-form-item>
            <el-form-item label="要求">
                <el-input :rows="10" type="textarea" v-model="dataForm.require" placeholder="" :disabled="true"></el-input>
            </el-form-item>

            <el-form-item label="审核意见">
                <el-input v-model="dataForm.checkReason" placeholder="" type="textarea"></el-input>
            </el-form-item>
        </el-form>

        <span slot="footer" class="dialog-footer">
            <el-button type="primary" @click="dataFormSubmit(1)">通过</el-button>
            <el-button type="primary" @click="dataFormSubmit(2)">拒绝</el-button>
            <el-button @click="visible = false">取消</el-button>
        </span>
    </el-dialog>
</template>
<script>
import API from '@/api';
import cloneDeep from 'lodash/cloneDeep';
export default {
    data() {
        return {
            typeOptions: [],
            visible: false,
            dataForm: {
                title: '',
                totalArea: '',
                address: '',
                type: '',
                deadline: '',
                checkReason:''
            },
        };
    },
    methods: {
        handleClose() {
            this.dataForm = {};
            this.$refs['dataForm'].resetFields();
        },
         //- 初始化
        init(id) {
            this.visible = true;
            this.getDetail(id);
        },
        getDetail(id) {
            API.iaInvestorder
                .lookiaInvestOrderDetail({
                    id: id
                })
                .then((res) => {
                    console.log(res);
                    this.dataForm = res.result;
                });
        },

        //- 通过或拒绝
        dataFormSubmit(type) {
            if (type == 2 && this.dataForm.checkReason == '') {
                // 拒绝
                this.$message.error('请填写审核意见，并说明拒绝原因');
                return;
            }

            var params = {
                checkReason: this.dataForm.checkReason,
                id: this.dataForm.id,
                checkStatus:type // 1:已通过;2:未通过
            };
        
            API.iaInvestorder.approveOrRejectAudit(params).then((data) => {
                    if (data.code == '0000') {
                        this.$message({
                            message: '操作成功',
                            type: 'success',
                            duration: 1500,
                            onClose: () => {
                                this.visible = false;
                                this.$emit('refreshDataList');
                            }
                        });
                    }
                });
        
        }
        
    }
};
</script>